package com.xw.mykotlin

import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.xw.kotlinlib.base.BaseViewModel
import com.xw.kotlinlib.network.NetDataUtil
import com.xw.kotlinlib.network.TResult
import kotlinx.coroutines.launch
import com.xw.mykotlin.PCategory as PCategory1

class MainViewModel(application: Application): BaseViewModel(application) {

    private val mRepositoryLiveData = MainRepository()
    val categorys = MutableLiveData<List<PCategory1>>()

    fun liveData(member_id: String?,build_type: Int?) {

        viewModelScope.launch {

            val res = mRepositoryLiveData.getCategory(member_id,build_type)
            if (res is TResult.Success) {
                categorys.value = res.data
            }

            if (res is TResult.Error) {
                val ex = NetDataUtil.getErrorCode(res)
            }
        }
    }
}